package cn.wolfcode.wolf2w.advice;

import cn.wolfcode.wolf2w.exception.LogicException;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 */
@ControllerAdvice
@ResponseBody
public class CommonExceptionHandler {
    /**
     * 处理自定义异常
     */
    @ExceptionHandler(LogicException.class)
    public Object handlerLogic(LogicException e){
        e.printStackTrace();
        return new JsonResult<>(500,e.getMessage(),null);
    }
    /**
     * 处理系统异常
     */
    @ExceptionHandler(RuntimeException.class)
    public Object handlerException(Exception e){
        e.printStackTrace();
        return JsonResult.defaultError();
    }
}
